var prefix = jsctx + "/parking";

var parkingGateStation = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageParkingGateStation",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    cache: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            tenantCode:$("#tenantCode").val(),
                            parkingSupplierId:$("#parkingSupplierId").val(),
                            status:'0'
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '',width:'50',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'stationName', title: '站点名称', align: 'center'},
                        {
                            field: 'bizType', title: '是否自营', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '自营'
                                } else if (value == '1') {
                                    return '非自营'
                                }
                            }
                        },
                        {field: 'createdTime', title: '创建时间', align: 'center'},
                        {
                            title: '操作',
                            field: 'roleId',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" onclick="parkingGateStation.offlineParkingGateStation('
                                    + row.elecStationId + ')">删除</a> ';
                                return a;
                            }
                        }
                    ]
                });
    }
    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        window.history.back();
    }
    
    function offlineParkingGateStation(elecStationId) {
        // alert(elecStationId);
        $.ajax({
            cache: false,
            type: "POST",
            url: prefix + "/deleteParkingGateStation",
            data:{
                elecStationId:elecStationId
            },
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.status == 200) {
                    reLoad();
                } else {
                    console.warn(data.message)
                }
            }
        });
    }

    function addParkingGate() {
        location.href = prefix + "/addParkingGate?parkingSupplierId=" + $("#parkingSupplierId").val();
    }



    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        offlineParkingGateStation:offlineParkingGateStation,
        addParkingGate:addParkingGate
    };
})();

